﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace 第三次课堂作业
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = 1;
            double totalArea = 0;
            string[] types = { "正方形", "长方形", "圆形" };
            shape[] shapes = new shape[10];
            Random random = new Random();
            while (num <= 10)
            {
                string type = types[random.Next(0, 3)];
                switch (type)
                {
                    case "正方形":
                        {
                            double side = Math.Round(random.NextDouble() * 100 - 50, 1);
                            square square = new square(side, "正方形" + num);
                            if (square.isLegel())
                            {
                                System.Console.WriteLine(square + "  ");
                                totalArea += square.getArea();
                                shapes[num - 1] = square;
                            }
                            else
                            {
                                System.Console.WriteLine(square + "  " + "非法正方形");
                                num--;
                            }

                        }; break;
                    case "长方形":
                        {
                            double length = Math.Round(random.NextDouble() * 100 - 50, 1);
                            double width = Math.Round(random.NextDouble() * 100 - 50, 1);
                            rectangle rec = new rectangle(length, width, "长方形" + num);
                            if (rec.isLegel())
                            {
                                System.Console.WriteLine(rec + "  ");
                                totalArea += rec.getArea();
                                shapes[num - 1] = rec;
                            }
                            else
                            {
                                System.Console.WriteLine(rec + "  " + "非法长方形");
                                num--;
                            }
                        }; break;
                    case "圆形":
                        {
                            double radius = Math.Round(random.NextDouble() * 100 - 50, 1);
                            circle circle = new circle(radius, "圆形" + num);
                            if (circle.isLegel())
                            {
                                System.Console.WriteLine(circle + "  ");
                                totalArea += circle.getArea();
                                shapes[num - 1] = circle;
                            }
                            else
                            {
                                System.Console.WriteLine(circle + "  " + "非法圆形");
                                num--;
                            }
                        }; break;
                    default:; break;
                }
                num++;
            }
            System.Console.WriteLine("");
            System.Console.WriteLine("最终十个图形为：");
            for (int i = 0; i < 10; i++)
            {
                System.Console.WriteLine(shapes[i]);
            }
            System.Console.WriteLine("");
            System.Console.WriteLine("总面积为：" + totalArea);
           
        }

        public abstract class shape
        {
            public static double sum;
            public abstract double getArea();
            public abstract bool isLegel();
        }
        //正方形类
        public class square:shape
        {
            private double side;
            private string name;
            public double Side
            {
                get { return side; }
                set { side = value; }
            }
            public square (double side, string v)
            {
                this.Side = side;
                this.name = v;
            }
            public override  double getArea()
            {
                return Math.Round(side * side,2);
            }
            public override bool isLegel()
            {
                if (side >0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            public override string ToString()
            {
                return (this.name + "的边长是：" + side +" 的面积:   " + getArea());
            }
        }

        //长方形类
        public class rectangle : shape
        {
            private double length, width;
            private string name;
            public double Length
            {
                get { return length; }
                set { length = value; }
            }
            public double Width
            {
                get { return width; }
                set { width = value; }
            }
            public rectangle(double length,double width, string v)
            {
                this.Length = length;
                this.Width = width;
                this.name = v;
            }
            public override double  getArea()
            {
                return Math.Round(length * width,2);
            }
            public override bool  isLegel()
            {
                if(width >0&&length >width)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            public override string ToString()
            {
                return (this.name + " 的面积:   " + getArea());
            }
        }

        //圆形类
        public class circle : shape
        {
            private double r;
            private string name;
            public double R
            {
                get { return r; }
                set { r = value; }
            }
            public circle(double r, string v)
            {
                this.R = r;
                this.name = v;
            }
            public override double getArea()
            {
                return Math.Round(3.14 * r * r,2);
            }
            public override bool isLegel()
            {
                if (r > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            public override string ToString()
            {
                return (this.name + " 的面积:   " + getArea());
            }
        }
    }
}

